#include "TRandom.h"

#include "yaml.h"
#include "YamlConfiger.hh"
#include "InputFileReader.hh"
#include "OutputFileWriter.hh"
#include "PMTContainer.hh"

#include "Digitization.hh"

Digitization::Digitization(){}
Digitization::~Digitization(){}

void Digitization::Processing()
{
    const YAML::Node* totalConfiger = YamlConfiger::GetInstance()->GetConfiger();
    gRandom->SetSeed((*totalConfiger)["RandomSeed"].as<int>());
    PMTContainer* pMTContainer = PMTContainer::GetInstance();
    InputFileReader* inputReader = new InputFileReader((*totalConfiger)["InputFile"]);
    OutputFileWriter* outputWriter = new OutputFileWriter((*totalConfiger)["OutputFile"]);

    while(1)
    {
        aSimEvent aEvent = inputReader->aEvent();
        if(aEvent.Type == -1)
        {
            break;
        }
        pMTContainer->ProcessEvent(aEvent);
        outputWriter->WriteEvent(aEvent);
    }
    outputWriter->SaveAll();

    delete inputReader;
    delete outputWriter;
    delete pMTContainer;
}